package demo4接口使用实例_1;

import java.util.Arrays;


public class Test {
    //给定一个学生对象数组，对这个对象数组中的元素进行排序(年龄降序)




    public static void main(String[] args) {
        Student[] students = new Student[] {
                new Student("张三",15),
                new Student("李四",12),
                new Student("王五",18),
                new Student("aaa",16)
        };
        Student student1 = new Student("zhangsan",10);
        Student student2 = new Student("lisi",15);

//        Arrays.sort(students);
//        System.out.println(Arrays.toString(students));
        //err
        //Exception in thread "main" java.lang.ClassCastException: class demo4接口使用实例.Student cannot be cast to class java.lang.Comparable
        // (demo4接口使用实例.Student is in unnamed module of loader 'app'; java.lang.Comparable is in module java.base of loader 'bootstrap')

        //sort排列的时候，拿什么排列都不知道，需要先将数组中元素与comparable有关系
        Arrays.sort(students, new AgeComparator());
        System.out.println(Arrays.toString(students));
    }
}
